package com.jic.veteran.portal.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.jic.veteran.portal.dao.RongjunshopDao;
import com.jic.veteran.portal.domain.DonationListDto;
import com.jic.veteran.portal.service.RongjunshopService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.ws.Action;
import java.math.BigDecimal;

@Slf4j
@Service
public class RongjunshopServiceImpl implements RongjunshopService {
    @Autowired
    private RongjunshopDao rongjunshopDao;
    @Override
    public DonationListDto getDonationInfoByOpenId(String openid,String startDate,String endDate) {
        DonationListDto donationListDto = rongjunshopDao.getDonationInfoByOpenId(openid,startDate,endDate);
        if(ObjectUtil.isEmpty(donationListDto)) {
            donationListDto.setAmount(BigDecimal.ZERO);
            donationListDto.setDonationCount(0);
        }
        if(!ObjectUtil.isEmpty(donationListDto) && null == donationListDto.getDonationCount()) {
            donationListDto.setDonationCount(0);
        }
        if(!ObjectUtil.isEmpty(donationListDto) && null == donationListDto.getAmount()) {
            donationListDto.setAmount(BigDecimal.ZERO);
        }
        return donationListDto;
    }

    @Override
    public String getOpenIdByUnionId(String unionid) {
        return rongjunshopDao.getOpenIdByUnionId(unionid);
    }
}
